package com.cskaoyan.service.admin.impl;

import com.cskaoyan.bean.MarketOrder;
import com.cskaoyan.bean.MarketOrderExample;
import com.cskaoyan.bean.param.DashboardVo;
import com.cskaoyan.mapper.DashboardMapper;
import com.cskaoyan.mapper.MarketOrderMapper;
import com.cskaoyan.service.admin.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Yan Dexuan
 * @since 2022/06/25 20:41
 */
@Service
public class DashboardServiceImpl implements DashboardService {

    @Autowired
    DashboardMapper dashboardMapper;

    @Autowired
    MarketOrderMapper marketOrderMapper;

    /**
     * 显示首页信息，包括用户数量，商品数量，货品数量和订单数量。
     *
     * @return com.cskaoyan.bean.param.DashboardVo
     * @author Yan Dexuan
     * @since 2022/06/25 21:09
     */
    @Override
    public DashboardVo dashboard() {

        Integer goodsTotal = dashboardMapper.queryGoodsTotal();
        Integer userTotal = dashboardMapper.queryUserTotal();
        Integer productTotal = dashboardMapper.queryProductTotal();
        Integer orderTotal = 0;

        MarketOrderExample example = new MarketOrderExample();
        List<MarketOrder> marketOrders = marketOrderMapper.selectByExample(example);
        for (MarketOrder marketOrder : marketOrders) {
            if (!marketOrder.getDeleted()) {
                orderTotal++;
            }
        }

        return DashboardVo.setDashboradVo(goodsTotal, userTotal, productTotal, orderTotal);
    }
}
